package com.heima.search.config;

import lombok.Getter;
import lombok.Setter;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Getter
@Setter
@Configuration
@ConfigurationProperties(prefix = "elasticsearch")
public class ElasticSearchConfig {
    private String host;
    private int port;


    @Bean
    public RestHighLevelClient client(){
        return new RestHighLevelClient(RestClient.builder(
                HttpHost.create("http://39.107.100.177:9200")
                //  new HttpHost("")
        ));
//    @Bean
//    public RestHighLevelClient client(){
//        System.out.println(host);
//        System.out.println(port);
//        return new RestHighLevelClient(RestClient.builder(
//                new HttpHost(
//                        host,
//                        port,
//                        "http"
//                )
//        ));
    }
}